/*
day254
2020.5.8
*/
#include<deque>
#include<vector>
#include<cstdlib> 
using namespace std;

struct TreeNode {
    int val;
	TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    bool btreeGameWinningMove(TreeNode* root, int n, int x) {
		TreeNode *target=find(root,x);
		
		int amount1=amount(target->left);
		int amount2=amount(target->right);
		int amount3=n-amount1-amount2-1;
		
		n/=2;
		
		return (amount1>n || amount2>n || amount3>n);
    }
    
    TreeNode *find(TreeNode *root,int x)
    {
    	if(!root)
    	{
    		return nullptr;
		}
    	
    	if(root->val==x)
    	{
    		return root;
		}
		
		TreeNode *l=find(root->left,x);
		TreeNode *r=find(root->right,x);
		
		if(l)
		{
			return l;
		}
		
		return r;
	}
    
    int amount(TreeNode *root)
    {
    	if(!root)
    	{
    		return 0;
		}
		
		return 1 + amount(root->left) + amount(root->right);
	}
};


int main()
{
	return 0;
 } 
